package application;




import java.io.File;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.scene.media.AudioClip;
import javafx.stage.Stage;

public class MainMenu{

	double scale;
	
	private AudioClip mouseEnterAudio; 
	private AudioClip mouseClickAudio;
	private ImageView playLabelImageView1;
	private ImageView playLabelImageView2;
	private ImageView settingsLabelImageView1;
	private ImageView settingsLabelImageView2;
	private ImageView mapDesignerLabelImageView1;
	private ImageView mapDesignerLabelImageView2;
	private ImageView exitLabelImageView1;
	private ImageView exitLabelImageView2;
	
	public MainMenu() {
		scale = BasicTools.scale.getValue();
		setButtonAudio(new AudioClip(new File("auds/MouseEnter.mp3").toURI().toString()), new AudioClip(new File("auds/MouseClick.mp3").toURI().toString()));
		setPlayLabelImageView(new ImageView("pics/PlayLabel1.png"), new ImageView("pics/PlayLabel2.png"));
		setSettingsLabelImageView(new ImageView("pics/SettingsLabel1.png"), new ImageView("pics/SettingsLabel2.png"));
		setMapDesignerLabelImageView(new ImageView("pics/MapDesignerLabel1.png"), new ImageView("pics/MapDesignerLabel2.png"));
		setExitLabelImageView(new ImageView("pics/ExitLabel1.png"), new ImageView("pics/ExitLabel2.png"));
	}
	
	public MainMenu(AudioClip mouseEnterAudio, AudioClip mouseClickAudio) {
		scale = BasicTools.scale.getValue();
		setButtonAudio(mouseEnterAudio, mouseClickAudio);
		setPlayLabelImageView(new ImageView("pics/PlayLabel1.png"), new ImageView("pics/PlayLabel2.png"));
		setSettingsLabelImageView(new ImageView("pics/SettingsLabel1.png"), new ImageView("pics/SettingsLabel2.png"));
		setMapDesignerLabelImageView(new ImageView("pics/MapDesignerLabel1.png"), new ImageView("pics/MapDesignerLabel2.png"));
		setExitLabelImageView(new ImageView("pics/ExitLabel1.png"), new ImageView("pics/ExitLabel2.png"));
	}
	
	public MainMenu(ImageView playLabelImageView1, ImageView playLabelImageView2, ImageView settingsLabelImageView1, ImageView settingsLabelImageView2,
			ImageView mapDesignerLabelImageView1, ImageView mapDesignerLabelImageView2, ImageView exitLabelImageView1, ImageView exitLabelImageView2) {
		scale = BasicTools.scale.getValue();
		setButtonAudio(new AudioClip(new File("auds/MouseEnter.mp3").toURI().toString()), new AudioClip(new File("auds/MouseClick.mp3").toURI().toString()));
		setPlayLabelImageView(playLabelImageView1, playLabelImageView2);
		setSettingsLabelImageView(settingsLabelImageView1, settingsLabelImageView2);
		setMapDesignerLabelImageView(mapDesignerLabelImageView1, mapDesignerLabelImageView2);
		setExitLabelImageView(exitLabelImageView1, exitLabelImageView2);
	}
	
	public MainMenu(AudioClip mouseEnterAudio, AudioClip mouseClickAudio,ImageView playLabelImageView1, ImageView playLabelImageView2, ImageView settingsLabelImageView1, ImageView settingsLabelImageView2,
			ImageView mapDesignerLabelImageView1, ImageView mapDesignerLabelImageView2, ImageView exitLabelImageView1, ImageView exitLabelImageView2 ) {
		setButtonAudio(mouseEnterAudio, mouseClickAudio);
		setPlayLabelImageView(playLabelImageView1, playLabelImageView2);
		setSettingsLabelImageView(settingsLabelImageView1, settingsLabelImageView2);
		setMapDesignerLabelImageView(mapDesignerLabelImageView1, mapDesignerLabelImageView2);
		setExitLabelImageView(exitLabelImageView1, exitLabelImageView2);
	}
	
	
		
	public void setButtonAudio(AudioClip mouseEnterAudio, AudioClip mouseClickAudio) {
		this.mouseEnterAudio = mouseEnterAudio;
		this.mouseClickAudio = mouseClickAudio;
	}
	
	public void setPlayLabelImageView(ImageView playLabelImageView1, ImageView playLabelImageView2) {
		this.playLabelImageView1 = playLabelImageView1;
		this.playLabelImageView2 = playLabelImageView2;
	}
	
	
	public void setSettingsLabelImageView(ImageView settingsLabelImageView1, ImageView settingsLabelImageView2) {
		this.settingsLabelImageView1 = settingsLabelImageView1;
		this.settingsLabelImageView2 = settingsLabelImageView2;
	}

	public void setMapDesignerLabelImageView(ImageView mapDesignerLabelImageView1, ImageView mapDesignerLabelImageView2) {
		this.mapDesignerLabelImageView1 = mapDesignerLabelImageView1;
		this.mapDesignerLabelImageView2 = mapDesignerLabelImageView2;
	}
	
	public void setExitLabelImageView(ImageView exitLabelImageView1, ImageView exitLabelImageView2) {
		this.exitLabelImageView1 = exitLabelImageView1;
		this.exitLabelImageView2 = exitLabelImageView2;
	}
	
	
	public  Scene getMainMenuScene(Stage primaryStage) {
		mouseEnterAudio.volumeProperty().bind(BasicTools.volumeValue);
		mouseClickAudio.volumeProperty().bind(BasicTools.volumeValue);
		Scene scene = new Scene(getMainMenuPane(primaryStage));
		return scene;	
	}
	
	public  VBox getMainMenuPane(Stage primarystage) {
		VBox mainMenuPane = new VBox();
		mainMenuPane.setPadding(new Insets(0, 0, 30 * scale , 0));
		mainMenuPane.setSpacing(20);
		mainMenuPane.setAlignment(Pos.BOTTOM_CENTER);
		
		mainMenuPane.getChildren().add(getPlayLabel(primarystage));
		mainMenuPane.getChildren().add(getMapDesignerLabel());
		mainMenuPane.getChildren().add(getSettingsLabel(primarystage));
		mainMenuPane.getChildren().add(getExitLabel(primarystage));
		mainMenuPane.setStyle("-fx-background-image: url(file:pics/MainMenuBackground.png); -fx-background-size: " + 
				BasicTools.windowSize[0] + " " + BasicTools.windowSize[1]);
		return mainMenuPane;
	}
	
	
	public  Label getPlayLabel(Stage primaryStage) {
		ImageView imageView1 = playLabelImageView1;
		ImageView imageView2 = playLabelImageView2;
		
		imageView1.setFitWidth(37 * 5 * scale);
		imageView1.setFitHeight(13 * 5 * scale);
		imageView2.setFitWidth(37 * 5 * scale);
		imageView2.setFitHeight(13 * 5 * scale);
		
		Label playLabel = new Label("", imageView1);

		playLabel.setOnMouseClicked(e ->{
			mouseClickAudio.play();
			BasicTools.changeSceneExpand(primaryStage, new LevelSelect().getLevleSelectScene(primaryStage));
		});
		
		playLabel.setOnMouseEntered(e ->{
			mouseEnterAudio.play();
			playLabel.setGraphic(imageView2);
			
			});
		
		playLabel.setOnMouseExited(e -> {
			playLabel.setGraphic(imageView1);
		});
		
		return playLabel;
	}
	
	
	public  Label getSettingsLabel(Stage primaryStage) {
		ImageView imageView1 = settingsLabelImageView1;
		ImageView imageView2 = settingsLabelImageView2;
		
		imageView1.setFitWidth(37 * 5 * scale);
		imageView1.setFitHeight(13 * 5 * scale);
		imageView2.setFitWidth(37 * 5 * scale);
		imageView2.setFitHeight(13 * 5 * scale);
		
		Label settingsLabel = new Label("", imageView1);
		
		settingsLabel.setOnMouseClicked(e ->{
			mouseClickAudio.play();
			BasicTools.changeSceneExpand(primaryStage, new Settings().getSettingsScene(primaryStage));
		});
		
		settingsLabel.setOnMouseEntered(e ->{
			mouseEnterAudio.play();
			settingsLabel.setGraphic(imageView2);
			
		});
		
		settingsLabel.setOnMouseExited(e -> {
			settingsLabel.setGraphic(imageView1);
		});

		return settingsLabel;
	}

	
	public  Label getMapDesignerLabel() {
		ImageView imageView1 = mapDesignerLabelImageView1;
		ImageView imageView2 = mapDesignerLabelImageView2;
		
		imageView1.setFitWidth(37 * 5 * scale);
		imageView1.setFitHeight(13 * 5 * scale);
		imageView2.setFitWidth(37 * 5 * scale);
		imageView2.setFitHeight(13 * 5 * scale);
		
		Label mapDesignerLabel = new Label("", imageView1);
		
		
		mapDesignerLabel.setOnMouseClicked(e -> {
			mouseClickAudio.play();
			BasicTools.launchStage(new MapDesigner());
		});
		
		mapDesignerLabel.setOnMouseEntered(e ->{
			mouseEnterAudio.play();
			mapDesignerLabel.setGraphic(imageView2);
			
		});
		
		mapDesignerLabel.setOnMouseExited(e -> {
			mapDesignerLabel.setGraphic(imageView1);
		});
		
		return mapDesignerLabel;
	}
	
	public  Label getExitLabel(Stage primaryStage) {
		ImageView imageView1 = exitLabelImageView1;
		ImageView imageView2 = exitLabelImageView2;
		
		imageView1.setFitWidth(37 * 5 * scale);
		imageView1.setFitHeight(13 * 5 * scale);
		imageView2.setFitWidth(37 * 5 * scale);
		imageView2.setFitHeight(13 * 5 * scale);
		
		Label ExitLabel = new Label("", imageView1);
		
		ExitLabel.setOnMouseClicked(e ->{
			mouseClickAudio.play();
			primaryStage.close();
		});
		
		ExitLabel.setOnMouseEntered(e ->{
			mouseEnterAudio.play();
			ExitLabel.setGraphic(imageView2);
			
		});
		
		ExitLabel.setOnMouseExited(e -> {
			ExitLabel.setGraphic(imageView1);
		});
		
		return ExitLabel;
	}
}
